<?php

require_once(APPPATH.'controllers/epicentr.php');

class Feed extends Epicentr {

	public function Feed() {
		parent::Epicentr();
	}
	
	public function index() {
    }
    
    
    public function whatsGoingOn($format = 'html', $jobid = false, $accesskey) {
    	$this->load->model('timesheetmodel');
    	$this->load->model('usersmodel');
    	
    	$usersearch = $this->usersmodel->find( array( 'md5|emailaddress' => $accesskey ) );
    	
    	if ($usersearch) $user = $usersearch[0];
    	else die();
    	
		$goingfrom = date('Y-m-d 00:00:00', mktime(0, 0, 0, date("m") , date("d") - 13, date("Y")));
		$goingto = date('Y-m-d 23:59:59', mktime(0, 0, 0, date("m") , date("d"), date("Y")));
		
		$updates = $this->timesheetmodel->whatsGoingOn(false, $user->id, $goingfrom, $goingto, true);
     	
    	$this->view_data['updates'] = $updates;
    	
    	switch ($format) {
			case "rss":
				$updatelist = $this->load->view('epicentr/content/timesheets/whatsgoingon-rss', $this->view_data, true);				
			break;
			case "html":
			default:
				$updatelist = $this->load->view('epicentr/content/timesheets/whatsgoingon', $this->view_data, true);
			break;
		}
    	
    	if ( strlen($updatelist) ) echo $updatelist;
    	else echo 0;
    	die();
    }
    
    public function whatsComingUp($format = 'html', $jobid = false, $accesskey) {
		$this->load->model('activitymodel');  
		$this->load->model('usersmodel');
		
		$usersearch = $this->usersmodel->find( array( 'md5|emailaddress' => $accesskey ) );
    	
    	if ($usersearch) $user = $usersearch[0];
    	else die();
		
		$comingfrom = date('Y-m-d 00:00:00', mktime(0, 0, 0, date("m") , date("d"), date("Y")));
		$comingto = date('Y-m-d 23:59:59', mktime(0, 0, 0, date("m") , date("d") + 14, date("Y")));
		
		$comingup = $this->activitymodel->whatsComingUp(false, $user->id, $comingfrom, $comingto);
		
		switch ($format) {
			case "rss":
				$cominguplist = $this->load->view('epicentr/content/timesheets/whatscomingup-rss', array('comingup' => $comingup), true);
			break;
			case "html":
			default:
				$cominguplist = $this->load->view('epicentr/content/timesheets/whatscomingup', array('comingup' => $comingup), true);
			break;
		}
		
		echo $cominguplist;die();
    }
    
}
?>